package cn.wolfcode.trip.base.domain;

import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;

import java.util.HashMap;
import java.util.Map;

/**
 * 旅游地区1
 */
@Setter
@Getter
public class Region extends BaseDomain{
    public static final int STATE_DISABLE = -1;//禁用
    public static final int STATE_COMMON = 0;//默认
    public static final int STATE_HOT = 1;//推荐

    //名称
    private String name;
    //上级地区
    private Region parent;
    //状态
    private Integer state = STATE_COMMON;

    public Map toTreeMap(){
        HashMap<String, Object> map = new HashMap<>();
        map.put("id",id);
        map.put("text",name);
        map.put("lazyLoad",true);//开启懒加载(页面上会有+号)
        if(state==Region.STATE_HOT) {
            map.put("tags", new String[]{"推荐"});
        }
        return map;
    }


    public String getJson(){
        Map<String,Object> map = new HashMap<>();
        //将需要的数据添加到map集合中
        map.put("id",id);
        map.put("name",name);
        map.put("state",state);
        if(parent!=null) {
            map.put("parentId", parent.getId());
            map.put("parentName", parent.getName());
        }
        //将map集合转换成json格式的字符串,再返回
        return JSON.toJSONString(map);
    }

}